package com.makingTeam.server.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.makingTeam.comment.annotation.ApiLog;
import com.makingTeam.comment.enums.OperateEnum;
import com.makingTeam.comment.result.JsonResult;
import com.makingTeam.server.service.Goods1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pzy
 * @since 2022-08-03
 */
@RestController
@RequestMapping("/system/goods1")
@Api(tags = "goodsdb1")
@Slf4j(topic = "api-log")
public class Goods1Controller {

    @Resource
    private Goods1Service goods1Service;



    @RequestMapping(value = "/open",method = RequestMethod.POST)
    @ApiOperation(value = "第一个入口方法")
    @ApiLog(method = "第一个入口方法",type= OperateEnum.QUEY)
    public JsonResult<Object> open(@RequestBody Object msg) throws Exception {
        log.info("测试接口。。。。。");
        log.info(JSON.toJSONString(msg));
        int uid=3;
        check(uid);
        service(uid);
        redis(uid);
        mysql(uid);
        String s="{\"code\":200,\"data\":[{\"KVP\":[{\"Key\":\"PGQ06-P-06_1\",\"Value\":\"5.5\"},{\"Key\":\"PGQ06-P-06_3\",\"Value\":\"5\"},{\"Key\":\"PGQ06-P-06_2\",\"Value\":\"6\"},{\"Key\":\"PGQ06-P-07_1\",\"Value\":\"3\"},{\"Key\":\"PGQ06-P-07_3\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-07_2\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-08_1\",\"Value\":\"5.5\"},{\"Key\":\"PGQ06-P-08_3\",\"Value\":\"5\"},{\"Key\":\"PGQ06-P-08_2\",\"Value\":\"6\"},{\"Key\":\"PGQ06-P-13_1\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-13_3\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-13_2\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-09_1\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-09_3\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-09_2\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-10_1\",\"Value\":\"7\"},{\"Key\":\"PGQ06-P-10_3\",\"Value\":\"6.5\"},{\"Key\":\"PGQ06-P-10_2\",\"Value\":\"7.5\"},{\"Key\":\"PGQ06-P-12_1\",\"Value\":\"8\"},{\"Key\":\"PGQ06-P-12_3\",\"Value\":\"7.5\"},{\"Key\":\"PGQ06-P-12_2\",\"Value\":\"8.5\"},{\"Key\":\"PGQ06-P-05_1\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-05_3\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-05_2\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-11_1\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-11_3\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-11_2\",\"Value\":\"\"},{\"Key\":\"PGQ06-P-04_1\",\"Value\":\"7\"},{\"Key\":\"PGQ06-P-04_3\",\"Value\":\"6.5\"},{\"Key\":\"PGQ06-P-04_2\",\"Value\":\"7.5\"}]}],\"flag\":true,\"msg\":\"获取参数成功。\"}";
        JSONObject jo= JSON.parseObject(s);
        System.out.println(jo);
        return JsonResult.success(jo.get("data"));
    }


    public void service(Integer uid) throws Exception {
        int count = 0;
        for (int i = 0; i < 10; i++) {
            count += i;
        }
        log.info("service  end {}", count);
    }

    public void redis(Integer uid) throws Exception {
        int count = 0;
        for (int i = 0; i < 10000; i++) {
            count += i;
        }
        log.info("redis  end {}", count);
    }

    public void mysql(Integer uid) throws Exception {
        long count = 0;
        for (int i = 0; i < 10000000; i++) {
            count += i;
        }
        log.info("mysql end {}", count);
    }

    public boolean check(Integer uid) throws Exception {
        if (uid == null || uid < 0) {
            log.error("uid不正确，uid:{}", uid);
            throw new Exception("uid不正确");
        }
        return true;
    }



}